package nollab.nolapp.app.toto.match;

import nollab.nolapp.app.toto.IRemoteService;
import nollab.nolapp.app.toto.IRemoteServiceCallback;
import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class MatchNotificationService extends Service {

	private IRemoteService mService;
	private Handler mHandler;
	
	private IRemoteServiceCallback mCallback  = new IRemoteServiceCallback.Stub() {
		
		@Override
		public void MessageCallback(int msg) throws RemoteException {
			// TODO Auto-generated method stub
			mHandler.sendEmptyMessage(msg);
		}
	};
	
	private ServiceConnection mConnection = new ServiceConnection() {
		
		@Override
		public void onServiceDisconnected(ComponentName name) {
			// TODO Auto-generated method stub
			mService = null;
		}
		
		@Override
		public void onServiceConnected(ComponentName name, IBinder service) {
			// TODO Auto-generated method stub
			mService = IRemoteService.Stub.asInterface(service);
			
			try {
				mService.registerCallback(mCallback);
			}
			catch (RemoteException e) {
				Log.e( "onServiceConnected error",e.toString());
			}
			
		}
	};
	
	
	@Override
	public IBinder onBind(Intent intent) {
		// TODO Auto-generated method stub
		
		if(IRemoteService.class.getName().equals(intent.getAction())) {
			IBinder mBinder = null;
			return mBinder;
		}
		
		return null;
	}
    

}
